<template>
  <div class="my-iconfont">
    <template v-if="type.includes('el-icon-')">
      <el-icon :size="fontSize">
        <component :is="type.replace('el-icon-', '')"></component>
      </el-icon>
    </template>
    <template v-else>
      <div class="iconfont" :class="type" :style="{ fontSize: fontSize }"></div>
    </template>
  </div>
</template>

<script setup>
import { computed } from "vue";
const props = defineProps({
  type: {
    type: String,
    require: false,
    default: "",
  },
  color: {
    type: String,
    require: false,
    default: "#606266",
  },
  size: {
    type: String || Number,
    require: false,
    default: "24px",
  },
});
const fontSize = computed(() => {
  if (typeof props.size === "number" && !isNaN(props.size)) {
    return props.size + "px";
  }
  return props.size;
});
</script>

<style scoped lang="scss">
.my-iconfont {
  height: v-bind(fontSize);
  width: v-bind(fontSize);
  line-height: v-bind(fontSize);
}
.el-icon svg {
  height: v-bind(fontSize);
  width: v-bind(fontSize);
}
</style>
